package com.zd.commodity.userMng.biz.impl;

import java.util.ArrayList;

import com.zd.commodity.biz.impl.BaseBiz;
import com.zd.commodity.userMng.biz.IRoleBiz;
import com.zd.commodity.userMng.dao.IMmenuDao;
import com.zd.commodity.userMng.dao.IRoleDao;
import com.zd.commodity.userMng.entity.Mmenu;
import com.zd.commodity.userMng.entity.Role;

public class RoleBiz extends BaseBiz<Role> implements IRoleBiz {
	private IRoleDao roleDao;
	private IMmenuDao mmenuDao;

	public IRoleDao getRoleDao() {
		return roleDao;
	}

	public void setRoleDao(IRoleDao roleDao) {
		this.roleDao = roleDao;
		this.setBaseDao(roleDao);
	}

	@Override
	public void updateRoleMenus(String menusStr, Long rid) {
		String[] menuIds = menusStr.split(",");
		Role role = roleDao.get(rid);
		role.setMenus(new ArrayList<Mmenu>());//先清空角色下的权限
		for (int i = 0; i < menuIds.length; i++) {
			Mmenu mmenu = mmenuDao.get(Long.parseLong(menuIds[i]));
			role.getMenus().add(mmenu);
		}
		
	}

	public IMmenuDao getMmenuDao() {
		return mmenuDao;
	}

	public void setMmenuDao(IMmenuDao mmenuDao) {
		this.mmenuDao = mmenuDao;
	}
}
